<?php
session_start();

class c_login extends CI_Controller{
    
    private $data;
    
    public function __construct(){
        parent::__construct();
        $this->load->helper("url");
        $this->load->model('m_model');
    }
    
    public function index(){
        if(!isset($_SESSION['username'])){
            $this->load->view("v_login.php", $this->data);
        }
        else{
            echo "<script>window.location.href='/st_admin'</script>";
        }
    }
    
    public function login(){
        $username = $_POST['user'];
        $password = $_POST['pass'];

        $result = $this->m_model->check_user_login($username, $password);
        if($result != 1){
            echo $result;
        }
        else{
            $_SESSION['username'] = $username;
            echo "/st_admin";
        }
    }

}